package com.agp.service.impl;

import com.agp.entity.Menu;
import com.agp.mapper.MenuMapper;
import com.agp.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    /**
     *
     * @param role 角色
     * @return
     */
    @Override
    public List<Menu> getMenuByRole(Integer role) {
        List<Menu> menuList=menuMapper.selectMenuTreeByRole(role);
        for (Menu menu : menuList) {
            //获取父菜单id
            Integer parentId=menu.getId();
            //根据父菜单id获取子菜单
           List<Menu>children=menuMapper.selectSubMenuByParentId(parentId,role);
          menu.setChildren(children);
        }
        return menuList;
    }
}
